const baseUrl = 'http://c597-183-236-85-101.ngrok.io'

const request = (url = '', data = {}, method = 'GET') => {
	return new Promise((resolve, reject) => {
		uni.request({
			method: method,
			url: baseUrl + url,
			data,
			header: {
				Authorization: uni.getStorageSync("token")
			},
			dataType: 'json',
		}).then((response) => {
			let [error, res] = response
			let { data } = res
			if (data.code == 200) {
				resolve(data);
			} else if(data.code != 401) {
				uni.showToast({
					icon: "none",
				    title: data.message,
				    duration: 60000
				});
				// if (data.need_auth) {
				// 	uni.clearStorage()
				// 	setTimeout(()=>{
				// 		uni.navigateTo({
				// 			url: "/pages/login/login"
				// 		})
				// 	}, 400)
				// }
			} else {
				uni.showToast({
					icon: "none",
				    title: data.message,
				    duration: 1500
				});
			}
		}).catch(error => {
			console.log(error)
			let [err, res] = error;
			reject(err)
		})
	});
}
export default request